$(function(){
    //大图Modal
    if(document.getElementById('largeImgModal')){
        var largeImg = new Vue({
            el:"#largeImgModal",
            data:{
                imgUrl : "",
                index: "",
                imgIndex:"",
            },
            methods:{
                nextImg:function(){
                    var count = blogInfo.blogBlock[this.index].largeUrls.length;

                    if(parseInt(this.imgIndex)+1 >= count){
                        this.imgIndex = 0;
                    }else{
                        this.imgIndex ++;
                    }

                    // this.setLargeImgSize(blogInfo,this.index,this.imgIndex);
                    this.imgUrl = blogInfo.blogBlock[this.index].largeUrls[this.imgIndex];
                },
                prevImg:function(){
                    var count = blogInfo.blogBlock[this.index].largeUrls.length;
                    if(parseInt(this.imgIndex)- 1 < 0){
                        this.imgIndex = count-1;
                    }else{
                        this.imgIndex --;
                    }
                    // this.setLargeImgSize(blogInfo,this.index,this.imgIndex);
                    this.imgUrl = blogInfo.blogBlock[this.index].largeUrls[this.imgIndex];
                },
                btnIn:function(type){
                    switch(parseInt(type)){
                        case 0:
                            // $('#largeImgModal .right-btn').css({'color':'rgba(255,255,255,1)'});
                            $('#largeImgModal .right-btn img').attr('src','image/largeRightActive.png');
                            break;
                        case 1:
                            // $('#largeImgModal .left-btn').css({'color':'rgba(255,255,255,1)'});
                            $('#largeImgModal .left-btn img').attr('src','image/largeLeftActive.png');
                            break;
                        case 2:
                            $('#largeImgModal .close-btn img').attr('src','image/largeCloseActive.png');
                            break;
                    }
                },
                btnOut: function(type){
                    switch(parseInt(type)){
                        case 0:
                            $('#largeImgModal .right-btn img').attr('src','image/largeRight.png');
                            break;
                        case 1:
                            $('#largeImgModal .left-btn img').attr('src','image/largeLeft.png');
                            break;
                        case 2:
                            $('#largeImgModal .close-btn img').attr('src','image/largeClose.png');
                            break;
                    }
                }
            },

        });
    }


    //我的货币详情
    var myInfo = new Vue({
        el:"#currency-price",
        data:{
            id:"",
            symbol: '',
            level: "",  //排名
            imgUrl: "", //币种图标
            symbolName: "", //全称
            zhName: "", //中文名
            price: "", //美元价格
            zhPrice: "",//人民币
            change: "", //涨幅
            isUp:false,//涨跌标志
            changeDate:"",//涨幅记录日期
            marketCap: "", //市值
            zhMarketCap: "", //市值 人民币
            isFavorite: false, //是否自选
            followId: "", //自选ID
            focusMsg: "" , //信息

            keys:"", //币种搜索讯息
        },
        methods:{
            getFocusMsg:function(){
                return this.isFavorite? '已关注': '关注';
            },
            setWarn:function(){
                if(!isLogin()){
                    location.href = 'login.html';
                }
                warn.usd = this.price;
                warn.cny = this.zhPrice;
                var left = ($(window).width()- 500)/2;
                var top = ($(window).height()- 556)/2;
                $('#warnModal').modal('show').css({
                    'margin-top':top,
                    'margin-left':left,
                    'width':500,
                    'height':556,
                });
                warn.imgUrl = this.imgUrl ;
                warn.name = warn.symbol = this.symbol;
                warn.usd = this.price;
                warn.cny = this.zhPrice;
                warn.id = this.id;

                //获取当前币种提醒列表
                var obj = {
                    remindingType: 0, //	提醒类型	否	1	Number	为空查询所有，0查询币种提醒，1 查询资产提醒
                    coinId: this.id, // 	币种	否	30	String   remindingType为0时，必填
                    pageSize: 10, //	每页条数	否	3	Number	默认10
                    pageNum: 1, //	第几页	否	3	Number	默认第一页
                    element: warn,
                };
                getRemindingsList(obj);
            },
            toggleFollow:function(){
                if(isLogin()) {
                    if(this.isFavorite){
                        var data = {
                            followId: this.followId, //	自选ID	是	2	String
                            element: this,
                        };
                        removeSelfChange(data);
                    }else{
                        var data = {
                            coinId: this.id, //	币种ID
                            focusType: 0 , //	自选类型 0 币种 1 交易对
                            element: this,
                        };
                        addSelfChange(data);
                    }
                }else{
                    if(this.isFavorite) {
                        //删除自选
                        var followList = $.cookie('followList').split(',');
                        for(var i=0; i<followList.length; i++){
                            if(followList[i] == this.id+':0'){
                                followList.splice(i,1);
                                break;
                            }
                        }
                        $.cookie('followList',followList.join(','))
                        this.focusMsg = '加自选';
                    }else{
                        //添加自选
                        if ($.cookie('followList')) {
                            var followList = $.cookie('followList').split(',');
                            if($.inArray(this.id+':0',followList) == -1){
                                $.cookie('followList', $.cookie('followList') + ',' + this.id+':0');
                            }
                        } else {
                            $.cookie('followList', this.id+':0');
                        }
                        this.focusMsg = '已自选';
                    }
                    this.isFavorite = !this.isFavorite;
                }


            },
        },
        mounted:function(){

            this.$nextTick(function(){
                var data = {
                    coinId : getUrlParams().id, //币种ID
                    myInfo : myInfo, //基本信息对象
                    guessing: guessing, //竞猜和基本数据
                    baseInfo: baseInfo, //基本数据
                    quickInfo:quickInfo, //快讯对象
                };
                getCoinProfile(data);
            });
        },
    });

    //币种信息 和 竞猜
    var guessing = new Vue({
        el:"#currency-info",
        data:{
            volumeEx: '', //成交额
            zhVolumeEx: '', //成交额人民币
            availableSupply: '', //流通数量
            supply: '', //发行总量
            netflow1d: '', //主力净流入
            inflow1d: '', //主力流入
            outflow1d: '', //主力流出
            marketCapRate: '', //市值占比
            liuRate: "", //流通率
            huanRate: "", //换手率

            symbol: "", //币种名称
            todayDate: getFullDate(new Date()) ,//当前时间
            coinId: getUrlParams().id, //货币ID
            currGuessType : 0 ,  // 0 看涨    1 看跌
            currChange: 3, //当前选择的看涨还是看跌  0看涨  1看跌
            addNum:1, //输入框默认积分
            totalNum: 0, //我的总积分
            upRate:"", //看涨比例
            downRate: "", //看跌比例
        },
        methods:{
            //竞猜积分
            toGuessing:function(type,$event){
                this.currGuessType = parseInt(type);
                if(type == this.currChange){
                    $('#currency-info .info-msg').removeClass('hidden');
                    $('#currency-info .my-info').addClass('hidden');

                    //按钮变色
                    $('#currency-info .info-up').removeClass('info-up-active');
                    $('#currency-info .info-down').removeClass('info-down-active');
                    this.currChange = 3;
                }else{
                    $('#currency-info .info-msg').addClass('hidden');
                    $('#currency-info .my-info').removeClass('hidden');

                    //按钮变色
                    $('#currency-info .info-up').removeClass('info-up-active');
                    $('#currency-info .info-down').removeClass('info-down-active');
                    switch(parseInt(type)){
                        case 0:
                            $('#currency-info .info-up').addClass('info-up-active');
                            this.currGuessTypee= this.currChange  = 0;
                            break;
                        case 1:
                            $('#currency-info .info-down').addClass('info-down-active');
                            this.currGuessType= this.currChange = 1;
                            break;
                    }

                }

            },
            //看大家怎么猜
            toSeeGuess: function(){
                $('#currency-info .info-right').addClass('hidden');
                $('#currency-info .my-jc-see').removeClass('hidden');
                //竞猜结果
                var data = {
                    coinId: getUrlParams().id, //	币种	否	30	String
                    element: this,
                };
                getGuessResult(data);

            },
            //竞猜首页
            toGuessDesc: function(){
                $('#currency-info .info-right').addClass('hidden');
                $('#currency-info .my-jc-desc').removeClass('hidden');
            },
            //确定竞猜
            toSubmitGuess: function(){
                if(isLogin()){
                    if(this.totalNum > 0 ){
                        //添加竞猜
                        var data = {
                            coinId: getUrlParams().id, //	币种	否	30	String
                            amount: this.addNum, //	竞猜积分数量	是	18.2	Number
                            guessFlag: this.currGuessType, //	涨跌标志	是	String	0 看涨 1 看跌
                            element: this,
                        };
                        addGuesses(data);
                    }else{
                        location.href = "personalGainInt.html";
                    }
                }else{
                    location.href = "login.html";
                }

            },
            //取消竞猜
            toCancelGuess: function(){
                $('#currency-info .my-jc-desc').removeClass('hidden');
                $('#currency-info .info-msg').removeClass('hidden');
                $('#currency-info .my-info').addClass('hidden');
                $('#currency-info .my-jc-result').addClass('hidden');

                //按钮变色
                $('#currency-info .info-up').removeClass('info-up-active');
                $('#currency-info .info-down').removeClass('info-down-active');
                this.currChange = 3;
            },
            //竞猜帮助
            toHelp: function(){
                $('#currency-info .info-right').addClass('hidden');
                $('#currency-info .my-jc-help').removeClass('hidden');
            },
            //积分投注 增加或减少
            setNum: function(type,event){

                    switch(parseInt(type)){
                        case 0: //减少
                            if(this.addNum -1 >= 0){
                                this.addNum--;
                            }
                            break;
                        case 1: //增加
                            if(isLogin()){
                                if(this.addNum +1 < this.totalNum ){
                                    this.addNum++;
                                }else{
                                    this.addNum = this.totalNum;
                                }
                            }else{
                                this.addNum++;
                            }

                            break;
                    }

            }
        },
        mounted:function(){
            this.$nextTick(function(){
                //获取我的积分
                getPoints({element: guessing});

            });
        }
    });

    //基本信息
    var baseInfo = new Vue({
        el: '#baseinfo-group',
        data:{
            symbolName: '' , //全称
            symbol: '', //英文
            publicTime: '', //发行时间
            exNum: 0, //上架交易所
            explorers: [],//区块浏览地址
            message: [],//社区论坛
            whitepaper:"", //白皮书
            github: "", //开源
            websites : [],//官网
            concept: [], //相关概念
            zhDescriptions:"", //中文概要
            enDescriptions:"", //英文概要
        },
        methods:{
            //相关概念
            toConcept:function(event){
                var id  =  event.currentTarget.getAttribute('value');
                location.href = 'currency.html?id='+id;
            },
        },
        mounted:function(){
            this.$nextTick(function(){
            });
        }
    });

    // 资讯导航信息
    var h = new Vue({
        el:'#information-nav',
        data:{
            currType: 1, // 1：相关资讯  2：交易所   3: 基本信息
        },
        methods:{
            changeNews: function(type,event){
                //导航颜色
                $('.news-nav').removeClass('nav-active');
                $(event.currentTarget).addClass('nav-active');
                this.currType = parseInt(type);
                $('.info-group').addClass('hidden');
                $('.no-data').addClass('hidden');
                switch(type){
                    case 1:
                        cancelLoad([siftInfo.loadData,twitterInfo.loadData,blogInfo.loadData,skillInfo.loadData]);
                        addLoad(quickInfo.loadData);
                        $('#news-group').removeClass('hidden');
                        break;
                    case 2:
                        cancelLoad([quickInfo.loadData,siftInfo.loadData,twitterInfo.loadData,blogInfo.loadData,skillInfo.loadData]);
                        $('#bourse-group').removeClass('hidden');
                        break;
                    case 3:
                        cancelLoad([quickInfo.loadData,siftInfo.loadData,twitterInfo.loadData,blogInfo.loadData,skillInfo.loadData]);
                        $('#baseinfo-group').removeClass('hidden');
                        break;
                    default:
                        alert('出错');

                }
            }
        },
    });



    //新闻列表
    var newsList = new Vue({
        el:"#news-header",
        data:{        },
        methods:{
            toSearch: function(event){
                var type = parseInt(event.currentTarget.getAttribute('value'));
                $('.filtrate-btn').removeClass('btn-active');
                $(event.currentTarget).addClass('btn-active');
                $('.news-box').addClass('hidden');
                $('.noData').addClass('hidden');
                $('.loadData').removeClass('hidden');
                //quickInfo  siftInfo twitterInfo  blogInfo  skillInfo
                switch(type){
                    case 1:
                        cancelLoad([siftInfo.loadData,twitterInfo.loadData,blogInfo.loadData,skillInfo.loadData]);
                        addLoad(quickInfo.loadData);
                        $('#quick-information').removeClass('hidden');

                        quickInfo.keys = myInfo.keys;
                        if(quickInfo.quickBlock.length == 0){
                            //获取动态资讯
                            var data = {
                                // infoType:'1' ,
                                pageSize:quickInfo.pageSize,
                                pageNum:quickInfo.currPage,
                                keyword:quickInfo.keyword,
                                element: quickInfo,
                                keys: myInfo.keys,
                            };
                            getQuikeList(data);
                        }else{
                            $('.loadData').addClass('hidden');
                        }
                        break;
                    case 4:
                        cancelLoad([quickInfo.loadData,twitterInfo.loadData,blogInfo.loadData,skillInfo.loadData]);
                        addLoad(siftInfo.loadData);
                        $('#sift-information').removeClass('hidden');
                        if(siftInfo.siftBlock.length == 0){
                            //获取技术分析
                            siftInfo.keys = myInfo.keys;
                            var data ={
                                infoType: '4', //	资讯类型	是	2	Number	4 精选资讯 5 技术分析
                                keyword	: siftInfo.keyword, //关键字	否	100	String	查询关键字
                                pageSize:siftInfo.pageSize, //	每页条数	否	9	Number	默认10，最大50
                                pageNum	: siftInfo.currPage, //第几页	否	9	Number	默认1
                                element: siftInfo,
                                keys: myInfo.keys,
                            };
                            getArticlesList(data);
                        }else{
                            $('.loadData').addClass('hidden');
                        }
                        break;
                    case 2:
                        cancelLoad([siftInfo.loadData,quickInfo.loadData,twitterInfo.loadData,skillInfo.loadData]);
                        addLoad(blogInfo.loadData);
                        $('#blog-information').removeClass('hidden');
                        if(blogInfo.blogBlock.length == 0){
                            //获取动态资讯
                            blogInfo.keys = myInfo.keys;
                            var data ={
                                infoType: '2', //	资讯类型	是	2	Number	2 微博 3twitter
                                keyword	: blogInfo.keyword, //关键字	否	100	String	查询关键字
                                pageSize:blogInfo.pageSize, //	每页条数	否	9	Number	默认10，最大50
                                pageNum	: blogInfo.currPage, //第几页	否	9	Number	默认1
                                element: blogInfo,
                                keys: myInfo.keys,
                            };
                            getDynamicList(data);
                        }else{
                            $('.loadData').addClass('hidden');
                        }
                        break;
                    case 3:
                        cancelLoad([siftInfo.loadData,blogInfo.loadData,quickInfo.loadData,skillInfo.loadData]);
                        addLoad(twitterInfo.loadData);
                        $('#twitter-information').removeClass('hidden');
                        if(twitterInfo.twitterBlock.length == 0){
                            //获取动态资讯
                            twitterInfo.keys = myInfo.keys;
                            var data ={
                                infoType: '3', //	资讯类型	是	2	Number	2 微博 3twitter
                                keyword	:twitterInfo.keyword, //关键字	否	100	String	查询关键字
                                pageSize:twitterInfo.pageSize, //	每页条数	否	9	Number	默认10，最大50
                                pageNum	: twitterInfo.currPage, //第几页	否	9	Number	默认1
                                element: twitterInfo,
                                keys: myInfo.keys,
                            };
                            getDynamicList(data);
                        }else{
                            $('.loadData').addClass('hidden');
                        }
                        break;
                    case 5:
                        cancelLoad([siftInfo.loadData,twitterInfo.loadData,blogInfo.loadData,quickInfo.loadData]);
                        addLoad(skillInfo.loadData);
                        $('#skill-information').removeClass('hidden');

                        // skillInfo.skillBlock = [];
                        if(skillInfo.skillBlock.length == 0){
                            //获取技术分析
                            skillInfo.keys = myInfo.keys;
                            var data ={
                                infoType: '5', //	资讯类型	是	2	Number	4 精选资讯 5 技术分析
                                keyword	: skillInfo.keyword, //关键字	否	100	String	查询关键字
                                pageSize:skillInfo.pageSize, //	每页条数	否	9	Number	默认10，最大50
                                pageNum	: skillInfo.currPage, //第几页	否	9	Number	默认1
                                element: skillInfo,
                                keys: myInfo.keys,
                            };
                            getArticlesList(data);
                        }else{
                            $('.loadData').addClass('hidden');
                        }
                        break;
                }
                //查找接口
                //获取当前页面类型  type 查找相应资讯

                var btnValue;
                if(event.currentTarget.type == 'text'){
                    btnValue =  event.currentTarget.value;
                }else{
                    btnValue = event.currentTarget.getAttribute('value');
                    if(btnValue==undefined || btnValue == null ){
                        btnValue = $(event.currentTarget).prev().val();
                    }else{
                        $('.filtrate-btn').removeClass('btn-active');
                        $(event.currentTarget).addClass('btn-active');
                    }
                }
                if(btnValue =='' || btnValue == null ||  btnValue== undefined){
                    $('.filtrate-input').focus();
                }else{
                    //查找接口
                    //获取当前页面类型  this.currType
                }
            },
        }
    });

    //24H快讯
    var quickInfo = new Vue({
        el: '#quick-information',
        data:{
            totalNum:0,
            currPage: 1,
            pageSize: 10,
            keys: "",
            keyword: getUrlParams().content ? decodeURI(getUrlParams().content) : "",
            //24H资讯
            quickBlock: { },
        },
        components:{
            'quick-content': quickComponent,
        },
        methods:{
            loadData:quickLoadData,
        },
        mounted:function(){
            this.$nextTick(function(){
                cancelLoad([quickInfo.loadData,siftInfo.loadData,twitterInfo.loadData,blogInfo.loadData,skillInfo.loadData]);
                addLoad(this.loadData);
            });
        },
    });


    //精选资讯
    var siftInfo = new Vue({
        el: '#sift-information',
        data:{
            totalNum:0,
            currPage: 1,
            pageSize: 10,
            keys: "",
            keyword: getUrlParams().content ? decodeURI(getUrlParams().content) : "",
            siftBlock: [],
        },
        components:{
            'sift-content': siftComponent,
        },
        methods:{
            //加载数据
            loadData: siftLoadData,
        },
        mounted:function(){
            if(document.getElementById('quick-information')){
                this.$nextTick(function(){
                });
            }
        }
    });


    //twitter
    var twitterInfo = new Vue({
        el: '#twitter-information',
        data:{
            totalNum:0,
            currPage: 1,
            pageSize:10,
            keys: "",
            keyword:getUrlParams().content ? decodeURI(getUrlParams().content) : "",
            twitterBlock: [],
        },
        methods:{
            loadData:twitterLoadData,
        },
        components:{
            'twitter-content': twitterComponent,
        },
        mounted:function(){
            this.$nextTick(function(){
            });
        }
    });


    //微博
    var blogInfo = new Vue({
        el: '#blog-information',
        data:{
            totalNum:0,
            currPage: 1,
            pageSize: 10,
            keys: "",
            keyword:getUrlParams().content ? decodeURI(getUrlParams().content) : "",
            largeImg: largeImg, //记录大图对象
            blogBlock: [ ],
        },
        methods:{
            //滚动加载
            loadData:blogLoadData,
        },
        components:{
            'blog-content': blogComponent,
        },
        mounted:function(){
            this.$nextTick(function(){
            });
        }
    });


    //技术分析
    var skillInfo = new Vue({
        el: '#skill-information',
        data:{
            totalNum:0,
            currPage: 1,
            pageSize: 10,
            keys: "",
            keyword:getUrlParams().content ? decodeURI(getUrlParams().content) : "",
            skillBlock: [],
        },
        components:{
            'skill-content': skillComponent,
        },
        methods:{
            loadData: skillLoadData,
        },
        mounted:function(){
            this.$nextTick(function(){
            });

        },
    });


    //交易所报价
    var bourse = new Vue({
        el: '#bourse-group',
        data:{
            bourseBlock: {
                totalNum: 1, //总页码
                currArea: [], //当前显示的页码LIST，最多9个
                maxPage: 9, //页面显示最大页码数
                currPage: 1, //当前页码
                // conceptId: "", //概念ID
                sortType: "", //排序类型
                sortWord:"", //排序字段
                pageSize:10, //页面行数
                keyWord: "", //关键字
                list: [ ],
            },
        },
        methods:{

            //获得当前是自选还是货币列表
            getCurrType: function(){
                return '2';
            },
            //跳转货币详细页
            goCurrencyProfile: function(event){
                var id = event.currentTarget.parentNode.getAttribute('value');
                // location.href = 'currencyProfile.html?id='+id;
                window.open( 'currencyProfile.html?id='+id);
            },


            //改变排序
            changeSort: changeSort,
            //根据当前页设置 显示页码行
            setCurrPage: setCurrPage,
            //数字翻页
            toPage: toPage,
            //跳转翻页
            jumpPage: jumpPage ,
            //设置每页行数
            setPageNum: setPageNum,

            //设置自选
            setFavorite:function(name,event){
                var id = event.currentTarget.parentNode.parentNode.getAttribute('value');
                var followId = event.currentTarget.parentNode.parentNode.getAttribute('followid');
                var index = event.currentTarget.parentNode.getAttribute('value');
                if(isLogin()) {
                    if (this[name].list[index].isFavorite) {
                        //取消自选
                        removeSelfChange({followId: followId,element:this[name],index:index});
                    } else {
                        //添加自选
                        addSelfChange({coinId: id, focusType: 1,element:this[name],index:index});
                    }
                }else{
                    if(this[name].list[index].isFavorite) {
                        //删除自选
                        var followList = $.cookie('followList').split(',');
                        for(var i=0; i<followList.length; i++){
                            if(followList[i] == id+':1'){
                                followList.splice(i,1);
                                break;
                            }
                        }
                        $.cookie('followList',followList.join(','))
                        // this.bourseBlock.list[index].isFavorite = false;
                    }else{
                        //添加自选
                        // console.log(this.bourseBlock.list[index].isFavorite);
                        if ($.cookie('followList')) {
                            var followList = $.cookie('followList').split(',');
                            if($.inArray(id+':1',followList) == -1){
                                $.cookie('followList', $.cookie('followList') + ',' + id+':1');
                            }
                        } else {
                            $.cookie('followList', id+':1');
                        }
                    }
                    this[name].list[index].isFavorite = !this[name].list[index].isFavorite;
                }
            },
            //运行哪个接口程序
            runCurrencyAPI:function(){
                switch(parseInt(this.getCurrType())){
                    case 2 :   //货币列表
                        //查询货币列表
                        var data = {
                            // conceptId:this.bourseBlock.conceptId, //概念ID
                            sortType:this.bourseBlock.sortType,  // 排序类型
                            sortWord:this.bourseBlock.sortWord, //排序字段
                            pageSize:this.bourseBlock.pageSize,  //每页显示条目
                            pageNum:this.bourseBlock.currPage,  //当前页
                            // keyword:this.bourseBlock.keyWord,  //搜索关键字
                            coinId: getUrlParams().id,
                            element: bourse,  //当前对象
                            tabType: 'bourseBlock',
                        };
                        getTickersList(data);

                        break;
                    case 1:    //自选
                        //查询自选
                        var data = {
                            sortType: this.optional.sortType, //	排序类型	否	1	String	0 升序 1 降序
                            sortWord: this.optional.sortWord, //	排序字段	否	20	String	传入对应字段名即可
                            element: this,
                            tabType : 'optional',
                        };
                        getCoinFocus(data);
                        break;
                    default:
                        alert('严重错误');
                }
            }

        },
        mounted:function(){
            this.$nextTick(function(){
                bourse.runCurrencyAPI();

            });
        },
    });









    // 走势图
    var flow = new Vue({
        el: '#currency-flow',
        data:{
            lineType : ['1d','1w','1m','3m','1y','ty','all'] ,
            newsList:[],
        },
        methods:{
            getDateStr: function(time){
                var now = new Date(time);
                var dateStr = "";

                var periodType = $('#currency-flow').find('.flow-btn-active').attr('value');
                switch(parseInt(periodType)){
                    case 0: //按天
                        dateStr = [addZero(now.getHours()),addZero(now.getMinutes())].join(':');
                        break;
                    case 1: //周
                        dateStr = [addZero(now.getMonth() + 1),addZero(now.getDate())].join('-');
                        break;
                    case 2: //月
                        dateStr = [addZero(now.getMonth() + 1),addZero(now.getDate())].join('-');
                        break;
                    case 3: //3个月
                        dateStr = [addZero(now.getMonth() + 1),addZero(now.getDate())].join('-');
                        break;
                    case 4: //1年
                        dateStr = [now.getFullYear(), addZero(now.getMonth() + 1),addZero(now.getDate())].join('-');
                        break;
                    case 5:  //今年
                        dateStr = [addZero(now.getMonth() + 1), addZero(now.getDate())].join('-');
                        break;
                    case 6: //所有
                        dateStr = [now.getFullYear(), addZero(now.getMonth() + 1),addZero(now.getDate())].join('-');
                        break;
                }
                return dateStr;
            },
            //设置折线图时间区间
            setDateArea: function(){
                var periodType = $('#currency-flow').find('.flow-btn-active').attr('value');
                //设置时间input
                var sDate = "";
                var eDate = "";
                var nDate = new Date();
                var nTimesteap = nDate.getTime();
                switch(parseInt(periodType)){
                    case 0: //按天
                        eDate = sDate = nDate.getFullYear()+'-'+addZero(nDate.getMonth()+1)+'-'+addZero(nDate.getDate());
                        break;
                    case 1: //周
                        eDate = nDate.getFullYear()+'-'+addZero(nDate.getMonth()+1)+'-'+addZero(nDate.getDate());
                        nTimesteap = nTimesteap - (3600*24*7*1000);
                        var tDate = new Date(nTimesteap);
                        sDate = tDate.getFullYear()+'-'+addZero(tDate.getMonth()+1)+'-'+addZero(tDate.getDate());
                        break;
                    case 2: //月
                        eDate = nDate.getFullYear()+'-'+addZero(nDate.getMonth()+1)+'-'+addZero(nDate.getDate());
                        nTimesteap = nTimesteap - (3600*24*30*1000);
                        var tDate = new Date(nTimesteap);
                        sDate = tDate.getFullYear()+'-'+addZero(tDate.getMonth()+1)+'-'+addZero(tDate.getDate());
                        break;
                    case 3: //3个月
                        eDate = nDate.getFullYear()+'-'+addZero(nDate.getMonth()+1)+'-'+addZero(nDate.getDate());
                        nTimesteap = nTimesteap - (3600*24*91*1000);
                        var tDate = new Date(nTimesteap);
                        sDate = tDate.getFullYear()+'-'+addZero(tDate.getMonth()+1)+'-'+addZero(tDate.getDate());
                        break;
                    case 4: //1年
                        eDate = nDate.getFullYear()+'-'+addZero(nDate.getMonth()+1)+'-'+addZero(nDate.getDate());
                        nTimesteap = nTimesteap - (3600*24*365*1000);
                        var tDate = new Date(nTimesteap);
                        sDate = tDate.getFullYear()+'-'+addZero(tDate.getMonth()+1)+'-'+addZero(tDate.getDate());
                        break;
                    case 5:  //今年
                        eDate = nDate.getFullYear()+'-'+addZero(nDate.getMonth()+1)+'-'+addZero(nDate.getDate());
                        sDate = nDate.getFullYear()+'-01-01';
                        break;
                    case 6: //所有
                        eDate = nDate.getFullYear()+'-'+addZero(nDate.getMonth()+1)+'-'+addZero(nDate.getDate());
                        sDate = '2001-01-01';
                        break;
                }
                $('.flow-date input').eq(0).val(sDate);
                $('.flow-date input').eq(1).val(eDate);
            },
            //点击月份按钮
            setFlow: function(event){
                // 按钮变色
                $('.flow-btn').removeClass('flow-btn-active');
                $(event.currentTarget).addClass('flow-btn-active');

                //获取币种价格历史
                var args = getUrlParams();
                var periodType = $('#currency-flow').find('.flow-btn-active').attr('value');
                var data = {coinId:args.id, periodType:this.lineType[periodType],element: this};
                getCoinHistory(data);

                this.setDateArea();

            },
            //生成当前点消息框
            getCurrInfo: function(index){
                if(this.newsList[index].newsList.length > 0){
                    var html = "<div id=\"flowinfo-box\">\n" +
                        "        <div class=\"info-list\">\n" +
                        "            <div class=\"info-date\">"+this.newsList[index].historyDate +"</div>\n" +
                        "            <div class=\"info-derc\"><span class=\"circle\"></span>价格(USD)：<span class=\"info-num\">"+this.newsList[index].price +"</span> USD</div>\n" +
                        "            <div class=\"info-derc\"><span class=\"circle circle2\"></span>24H成交额：<span class=\"info-num\">"+this.newsList[index].volume +"</span> USD</div>\n" +
                        "        </div>\n" +
                        "        <div class=\"news-list\">\n" ;
                        for(var j=0; j<this.newsList[index].newsList.length; j++){
                            html+="            <div class=\"news-item\" value=\""+index+"\"><div class=\"news-sing\">"+(j+1)+"</div><div class=\"flow-news-item pointer\" value=\""+j+"\" index=\""+index+"\">"+this.newsList[index].newsList[j].titleBack +"</div></div>\n" +
                                "            <div class=\"clearfix\"></div>";
                        }
                        html+="        </div>\n" +
                        "    </div>";
                    return html;
                }else{
                    var html = "<div id=\"flowinfo-box\">\n" +
                        "        <div class=\"info-list\">\n" +
                        "            <div class=\"info-date\">"+this.newsList[index].historyDate +"</div>\n" +
                        "            <div class=\"info-derc\"><span class=\"circle\"></span>价格(USD)：<span class=\"info-num\">"+this.newsList[index].price +"</span> USD</div>\n" +
                        "            <div class=\"info-derc\"><span class=\"circle circle2\"></span>24H成交额: <span class=\"info-num\">"+this.newsList[index].volume +"</span> USD</div>\n" +
                        "        </div>\n" +
                        "        <div class=\"news-list\">\n" +
                        "            <div class=\"news-item text-center\">没有相关资讯</div>\n" +
                        "        </div>\n" +
                        "    </div>";
                    return html;
                }
            },
            //画折线图
            drawFlow: function(date,data,data2,priceMin,priceMax,volMin,volMax){
                // 走势图
                var myFlow = echarts.init(document.getElementById('flow-img'));
                // var periodType = $('#currency-flow').find('.flow-btn-active').attr('value');
                if(date.length > 7){
                    var interval =  Math.ceil(date.length / 6 );
                }else{
                    var interval = 0;
                }
                if(priceMax - priceMin < 1){
                    var yInterval = setBitNum(priceMax - priceMin, 2)/5 ;
                    var yInterval2 = Math.round((volMax - volMin)/5 );
                }else{
                    var yInterval = Math.round((priceMax - priceMin)/5 );
                    var yInterval2 = Math.round((volMax - volMin)/5 );
                }
                var option = {
                    textStyle: { //行样式
                        color: 'rgba(153,153,153,1)',
                        fontWeight:'500',
                        fontSize:13,
                        fontFamily:'Microsoft YaHei',
                    },
                    dataZoom:{
                        xAxisIndex: [0, 1]
                    },

                    tooltip: [{
                        backgroundColor:'none',  //悬浮框背景色
                        trigger: 'axis',
                        padding:0,
                        // triggerOn:'click',
                        axisPointer:{
                            type: 'line',
                            label:{
                                formatter:function(params){
                                },
                            },
                            lineStyle:{
                                width: 1,  //竖线宽度
                            },
                        },
                        formatter:function(params){
                            return flow.getCurrInfo(params[0].dataIndex);
                        },
                        // alwaysShowContent: true,  //一直显示悬浮框
                        showDelay: 100,   // 延迟显示出来
                        hideDelay: 200, //延迟隐藏起来
                        enterable: true, //鼠标是否可以进入悬浮框
                        confine: false, //悬浮框限定在图标内
                        transitionDuration:0.1, //悬浮框出现动画
                        //悬浮框位置
                        position: function (point, params, dom, rect, size) {
                            // point: 鼠标位置，如 [20, 40]。
                            // params: 同 formatter 的参数相同。
                            // dom: tooltip 的 dom 对象。
                            // rect: 只有鼠标在图形上时有效，是一个用x, y, width, height四个属性表达的图形包围盒。
                            // size: 包括 dom 的尺寸和 echarts 容器的当前尺寸，例如：{contentSize: [width, height], viewSize: [width, height]}。
                            return [point[0]+5,point[1]+5];


                        }
                    }],
                    xAxis: [{
                        boundaryGap: [0, '100%'],
                        axisLabel:{interval: interval, show:false,},  //x轴间隔显示
                        axisTick:{  //刻度线
                            show:false,
                        },
                        axisLine:{
                            lineStyle:{
                                color:'rgba(237,237,237,0.5)',
                            },
                        },
                        data: date,
                        gridIndex: 0
                    }, {
                        boundaryGap: [0, '100%'],
                        axisLabel:{interval:interval, show:true,showMaxLabel: true,showMinLabel: true},  //x轴间隔显示
                        axisTick:{  //刻度线
                            show:false,
                        },
                        axisLine:{
                            lineStyle:{
                                color:'rgba(237, 237, 237, 1)',
                            },
                        },
                        data: date,
                        gridIndex: 1
                    }],
                    yAxis: [{
                        min: priceMin,
                        max: priceMax ,
                        interval: yInterval,
                        boundaryGap:false,
                        position:'right',
                        axisLine:{
                            lineStyle:{
                                color:'rgba(237, 237, 237, 1)',
                            }
                        },
                        axisLabel:{interval: interval, show:true,showMaxLabel: true,showMinLabel: true},  //x轴间隔显示
                        axisTick:{  //刻度线
                            show:false,
                        },
                        splitLine: {
                            show: true,
                            lineStyle: {
                                // 使用深浅的间隔色
                                color:'rgba(237, 237, 237, 1)',
                            }},
                    }, {
                        name:'24h交易量',
                        nameLocation: 'center',
                        nameStyle: {
                            color: 'rgba(153,153,153,1)',
                            fontSize: 13,
                        },
                        // min: volMin,
                        max: volMax,
                        min: volMin,
                        interval: yInterval2,
                        // boundaryGap: [0, '100%'],
                        boundaryGap:false,
                        axisLine:{
                            lineStyle:{
                                color:'rgba(237, 237, 237, 1)',
                            }
                        },
                        splitLine: {show: false,},
                        position:'left',
                        gridIndex: 1,
                        axisLabel:{interval: interval, show:false,},  //Y轴间隔显示
                        axisTick:{  //刻度线
                            show:false,
                        },
                    }],
                    grid: [{
                        bottom: '40%',
                        left:'3%',
                        right:'6%',
                    }, {
                        top: '67%',
                        left:'3%',
                        right:'6%',
                        bottom:'20%',
                    }],
                    series: [{
                        type: 'line',
                        showSymbol: false,
                        smooth:true,
                        data: data,
                        itemStyle: {
                            normal: {
                                color: 'rgba(93, 144, 247, 1)',
                            },
                            color: 'rgba(93, 144, 247, 1)',
                        },
                        lineStyle:{
                            color:'rgba(93, 144, 247, 1)',
                        },
                        areaStyle: {
                            normal: {
                                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                    offset: 0,
                                    color: 'rgba(93, 144, 247, 0.16)'
                                }, {
                                    offset: 1,
                                    color: 'rgba(93, 144, 247, 0)'
                                }]),

                            }
                        },
                    }, {
                        type: 'bar',
                        showSymbol: false,
                        data: data2,
                        xAxisIndex: 1,
                        yAxisIndex: 1,
                        smooth:true,
                        symbol: 'none',
                        sampling: 'average',
                        itemStyle: {
                            normal: {
                                color: 'rgba(93, 144, 247, 0.2)',
                            }
                        },
                        barWidth:'8px',
                    }]
                };

                // 使用刚指定的配置项和数据显示图表。
                myFlow.setOption(option,true);
            },
        },
        mounted:function(){
            this.$nextTick(function(){

                //获取币种价格历史
                var args = getUrlParams();
                var periodType = $('#currency-flow').find('.flow-btn-active').attr('value');
                getCoinHistory({coinId:args.id, periodType:flow.lineType[periodType],element:flow});
                flow.setDateArea();
            });
        }
    });

    //走势图相应点新闻弹出Modal
    $('#currency-flow').on('click','.flow-news-item',function(){
        var index = $(this).attr('index');
        var newsIndex = $(this).attr('value');

        var time = getTimeType(flow.newsList[index].newsList[newsIndex].time);
        if(time.type == 'today'){
            historyNews.time  = '今天  '+ time.time;
        }else{
            historyNews.time  =  time.type + '  '+ time.time;
        }
        historyNews.title = flow.newsList[index].newsList[newsIndex].title;
        historyNews.source = flow.newsList[index].newsList[newsIndex].source;
        historyNews.content = flow.newsList[index].newsList[newsIndex].content;
        $('#flowinfo-box').addClass('hidden');
        $('#newsModal').modal({backdrop:'static',});
        // $('#newsModal').modal('show');
        var left = ($(window).width()-500)/2;
        var top = ($(window).height()-460)/2;
        $('#newsModal').modal('show').css({
            'margin-top':top,
            'margin-left':left,
            'width':500,
            'min-height':460,
        });
    });

    // 设置币种提醒
    var warn = new Vue({
        el:'#warnModal',
        data:{
            imgUrl: "",
            name: "BTC" ,
            symbol:"BTC",
            usd: "5,0,000.00",
            cny: "12,000,0.00",
            id: "",

            upNum:"",
            upPriceType:0,
            downNum:"",
            downPriceType:0,
            priceType:['元','美元'], //对应 list.type
            singleType:['空','上涨','下跌'],  //对应 list.single
            list:[],
        },
        methods:{
            cancelWarn:function(event){
                //调用添加接口，结构执行成功，才执行以下内容
                var index = event.currentTarget.getAttribute('value');
                var obj ={
                    remindingId: this.list[index].id, //提醒ID
                    coinId: this.list[index].coinId, //货币ID
                    index: index, //删除的序列号
                    element: this,
                };
                removeRemindings(obj);
            },
            addWarn: function(event){
                if($(event.currentTarget).hasClass('btn-active')){
                    if(isLogin()){
                        var single = event.currentTarget.getAttribute('value');  // 1 上涨比例 2 下跌比例
                        // var coinId = event.currentTarget.getAttribute('coinid');
                        switch (parseInt(single)) {
                            case 1:
                                var price = this.upNum;
                                var priceType = this.upPriceType;
                                break;
                            case 2:
                                var price = this.downNum;
                                var priceType = this.downPriceType;
                                break;
                            default:
                                var price = 0;
                                var priceType = 0;
                        }
                        // console.log(single+' ---> '+price+' ----  '+ priceType);
                        if(parseInt(price) > 0 ){
                            //调用添加接口，结构执行成功，才执行以下内容
                            var obj ={
                                remindingType: 0, //	预警类型	是	1	Number	0 币种 1 资产
                                remindingFlag: single,//	预警标志	是	1	Number	0 金额 1 上涨比例 2 下跌比例
                                remindingAmt: price,	//预警额度	是	18,6	Number
                                currency: priceType, //	单位	String	是	币种单位，0 人民币 1 美元
                                coinId: this.id, //币种ID
                                element: this,
                            };
                            addRemindings(obj);
                        }else{
                            $(event.currentTarget).parent().find('.warn-btn').removeClass('btn-active');
                            alert('输入有误');
                        }
                    }else{
                        location.href="login.html";
                    }

                }
            },
            //监测输入框数据是否符合规则，
            checkInput:function(event){
                var strReg = /^[0-9]+.?[0-9]*$/g;
                var value = $(event.currentTarget).parent().find('.price-input').val();
                if(strReg.test(value)){
                    // alert('成功');
                    if(!$(event.currentTarget).parent().find('.warn-btn').hasClass('btn-active')){
                        $(event.currentTarget).parent().find('.warn-btn').addClass('btn-active');
                    }
                }else{
                    // alert('失败');
                    $(event.currentTarget).parent().find('.warn-btn').removeClass('btn-active');
                }

            }
        },
        watch:{
        }
    });


    // 设置折线图弹出快讯内容
    var historyNews = new Vue({
        el:'#newsModal',
        data:{
            time: "" ,
            title: "",
            content: "",
            source:"",
        },
        methods:{

        },
    });





});